<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Siteuser_model extends My_Model
{    
    public function __construct()
    {
        parent::__construct();
        $this->model_name="????";
        $this->tablename="sites_user";  
    }


    public function getpage($siteid,$page,$pagesize=0,$key="",$all=0){
        $where=[];
        if($siteid>0)
        {
            $where=["siteid"=>$siteid];
        }
        if($pagesize>0)
        {
            $this->pagesize=$pagesize;
        }
        if($key)
        {
            $key=["email"=>$key,"realname"=>$key];
        }
        if($all==1)
        {
            $url="/backend/clients";
        }
        else
        {
            $url="backend/sites/client/index/".$siteid;
        }
        return $this->get_items_by_page($where,$page,$url,"id desc",[],$key);                
    }




    public function getusercount($siteid)
    {
        $where=["siteid"=>$siteid];
        $count=$this->getcount($where);
        return $count;
    }

    public function checkcategory($siteid,$rid)
    {


    }


    public function getall(){
        
        $where=[];

        return $this->get_items_by_where($where);                
    }

    public function delitem($id)
    {
        $where=["id"=>$id];
        $this->delete($where);
        return true;
    }

    public function getitembyid($id){
        $where=array("id"=>$id);
  
        return $this->get_item_by_where($where);
    }

    
    public function create($data){

        return $this->add_item($data);       
    }

    public function update($id,$data){

        if(is_array($id))
        {
            $where="id in (".implode(",",$id).")";
           
        }else{
            $where=array("id"=>$id);
           
        }
        return $this->update_item($where,$data);

    }

   
}